﻿var GeoConverter = Geo.CoordinateConverter;
test("CoordinateConverter Formats 40.446454 -79.976875", function () {
    var expectedResult = new GeoConverter.Model.CoordinateDmsInfo(new GeoConverter.Model.DmsInfo(GeoConverter.Enumerations.DirectionTypes.North, 40, 26, 47.2), new GeoConverter.Model.DmsInfo(GeoConverter.Enumerations.DirectionTypes.West, 79, 58, 36.75));
    var formats = new Array();
    formats[0] = '40.446454 -79.976875';
    formats[1] = '40.446454,-79.976875';
    formats[2] = '40.446454N 79.976875W';
    formats[3] = '40:26:47.2N 079:58:36.75W';
    formats[4] = '40°26\'47"N 079°58\'37"W';
    formats[5] = '40°26′47″N 079°58′37″W';
    formats[6] = '40d 26\' 47" N 079d 58\' 37" W';
    formats[7] = '40d 26′ 47″ N 079d 58′ 37″ W';
    formats[8] = '40d 26′ 47″ N -079d 58′ 37″';
    formats[9] = '40° 26.78724, -79° 58.61250';
    formats[10] = '40d 26.78724, -79d 58.61250';
    formats[11] = '40.4464540, -79.9768750';
    formats[12] = '40°26′47″N 079°58′37″W';
    formats[13] = '40°26\'47"N 079°58\'37"W';
    formats[14] = '40d 26\'47" 079d 58\'37"W';
    formats[15] = '40d 26\'47"N 079d 58\'37"W';
    formats[16] = '40d 26′47″N 079°58′37″W';
    formats[17] = '40 26 47 N 079 58 37 W';
    formats[18] = '40 26 47N 079 58 37W';
    formats[19] = 'N 40d 26 47  W 079 58 37';
    formats[20] = 'N40d 26 47 079 58 37W';
    formats[21] = '40d 26 47N 079 58 37W';
    formats[22] = 'N40d 26 47 -079 58 37';
    formats[23] = 'N40* 26.78724\'  W079* 58.61250\'';
    formats[23] = 'W079* 58.61250\'  N40* 26.78724\'';
    var dmsConverter = new GeoConverter.Providers.DecimalAndDmsConverter();
    for(var i = 0; i < formats.length; i++) {
        var input = formats[i];
        var output = dmsConverter.ParseCoordinateDms(input);
        equal(output.DmsLatitude.DirectionType, expectedResult.DmsLatitude.DirectionType, 'N DirectionType RESULT input=' + input + ', output=' + output.DmsLatitude.DirectionType + ', expected=' + expectedResult.DmsLatitude.DirectionType);
        equal(output.DmsLatitude.Degrees, expectedResult.DmsLatitude.Degrees, 'N Degrees RESULT input=' + input + ', output=' + output.DmsLatitude.Degrees + ', expected=' + expectedResult.DmsLatitude.Degrees);
        equal(output.DmsLatitude.Minutes, expectedResult.DmsLatitude.Minutes, 'N Minutes RESULT input=' + input + ', output=' + output.DmsLatitude.Minutes + ', expected=' + expectedResult.DmsLatitude.Minutes);
        equal(Math.round(output.DmsLatitude.Seconds), Math.round(expectedResult.DmsLatitude.Seconds), 'N Seconds RESULT input=' + input + ', output=' + output.DmsLatitude.Seconds + ', expected=' + expectedResult.DmsLatitude.Seconds + '(round)');
        equal(output.DmsLongitude.DirectionType, expectedResult.DmsLongitude.DirectionType, 'W DirectionType RESULT input=' + input + ', output=' + output.DmsLongitude.DirectionType + ', expected=' + expectedResult.DmsLongitude.DirectionType);
        equal(output.DmsLongitude.Degrees, expectedResult.DmsLongitude.Degrees, 'W Degrees RESULT input=' + input + ', output=' + output.DmsLongitude.Degrees + ', expected=' + expectedResult.DmsLongitude.Degrees);
        equal(output.DmsLongitude.Minutes, expectedResult.DmsLongitude.Minutes, 'W Minutes RESULT input=' + input + ', output=' + output.DmsLongitude.Minutes + ', expected=' + expectedResult.DmsLongitude.Minutes);
        equal(Math.round(output.DmsLongitude.Seconds), Math.round(expectedResult.DmsLongitude.Seconds), 'W Seconds RESULT input=' + input + ', output=' + output.DmsLongitude.Seconds + ', expected=' + expectedResult.DmsLongitude.Seconds + '(round)');
    }
});
test("CoordinateConverter Formats -41.877518 146.760986", function () {
    var expectedResult = new GeoConverter.Model.CoordinateDmsInfo(new GeoConverter.Model.DmsInfo(GeoConverter.Enumerations.DirectionTypes.South, 41, 52, 39.0648), new GeoConverter.Model.DmsInfo(GeoConverter.Enumerations.DirectionTypes.East, 146, 45, 39.5496));
    var formats = new Array();
    formats[0] = '-41.877518 146.760986';
    formats[1] = '-41.877518,146.760986';
    formats[2] = '-41.8775180°, 146.7609860°';
    formats[3] = '-41°52.65108\', 146°45.65916\'';
    formats[4] = '-41°52\'39.0648", 146°45\'39.5496"';
    formats[5] = 'S41 52 39	E146 45 40';
    formats[6] = 'S 41 52.651	E 146 45.659';
    formats[7] = 'S41D 52 39	E146D 45 40';
    formats[8] = 'S41D 52.651	E146D 45.659';
    formats[9] = 'N41* 52.651\'  E146* 45.65916\'';
    formats[10] = 'E146* 45.65916\'  N41* 52.651\'';
    var dmsConverter = new GeoConverter.Providers.DecimalAndDmsConverter();
    for(var i = 0; i < formats.length; i++) {
        var input = formats[i];
        var output = dmsConverter.ParseCoordinateDms(input);
        equal(output.DmsLatitude.DirectionType, expectedResult.DmsLatitude.DirectionType, 'N DirectionType RESULT input=' + input + ', output=' + output.DmsLatitude.DirectionType + ', expected=' + expectedResult.DmsLatitude.DirectionType);
        equal(output.DmsLatitude.Degrees, expectedResult.DmsLatitude.Degrees, 'N Degrees RESULT input=' + input + ', output=' + output.DmsLatitude.Degrees + ', expected=' + expectedResult.DmsLatitude.Degrees);
        equal(output.DmsLatitude.Minutes, expectedResult.DmsLatitude.Minutes, 'N Minutes RESULT input=' + input + ', output=' + output.DmsLatitude.Minutes + ', expected=' + expectedResult.DmsLatitude.Minutes);
        equal(Math.round(output.DmsLatitude.Seconds), Math.round(expectedResult.DmsLatitude.Seconds), 'N Seconds RESULT input=' + input + ', output=' + output.DmsLatitude.Seconds + ', expected=' + expectedResult.DmsLatitude.Seconds + '(round)');
        equal(output.DmsLongitude.DirectionType, expectedResult.DmsLongitude.DirectionType, 'W DirectionType RESULT input=' + input + ', output=' + output.DmsLongitude.DirectionType + ', expected=' + expectedResult.DmsLongitude.DirectionType);
        equal(output.DmsLongitude.Degrees, expectedResult.DmsLongitude.Degrees, 'W Degrees RESULT input=' + input + ', output=' + output.DmsLongitude.Degrees + ', expected=' + expectedResult.DmsLongitude.Degrees);
        equal(output.DmsLongitude.Minutes, expectedResult.DmsLongitude.Minutes, 'W Minutes RESULT input=' + input + ', output=' + output.DmsLongitude.Minutes + ', expected=' + expectedResult.DmsLongitude.Minutes);
        equal(Math.round(output.DmsLongitude.Seconds), Math.round(expectedResult.DmsLongitude.Seconds), 'W Seconds RESULT input=' + input + ', output=' + output.DmsLongitude.Seconds + ', expected=' + expectedResult.DmsLongitude.Seconds + '(round)');
    }
});
test("CoordinateConverter Formats 40.446454 -79.976875", function () {
    var input = "40.446454 -79.976875";
    var dmsConverter = new GeoConverter.Providers.DecimalAndDmsConverter();
    var dmsExpectedResult = "N 40°26'47.2344\", W 79°58'36.75\"";
    var dmsOutput = dmsConverter.ParseCoordinateDms(input);
    equal(dmsOutput.ToString(), dmsExpectedResult, 'DMS  dmsOutput:' + dmsOutput.ToString() + ', dmsExpectedResult:' + dmsExpectedResult);
    var decimalExpectedResult = "40.446454, -79.976875";
    var decimalOutput = dmsOutput.ToCoordinateDecimal();
    equal(decimalOutput.ToString(), decimalExpectedResult, 'DMS ToCoordinateDecimal decimalOutput:' + decimalOutput.ToString() + ', decimalExpectedResult:' + decimalExpectedResult);
    var dmExpectedResult = "N 40°26.78724\", W 79°58.6125\"";
    var dmOutput = decimalOutput.ToCoordinateDm();
    equal(dmOutput.ToString(), dmExpectedResult, 'Decimal ToCoordinateDm dmOutput:' + dmOutput.ToString() + ', dmExpectedResult:' + dmExpectedResult);
    decimalOutput = dmOutput.ToCoordinateDecimal();
    equal(decimalOutput.ToString(), decimalExpectedResult, 'Dm ToCoordinateDecimal DecimalOutput:' + decimalOutput.ToString() + ', decimalExpectedResult:' + decimalExpectedResult);
    dmsOutput = decimalOutput.ToCoordinateDms();
    equal(dmsOutput.ToString(), dmsExpectedResult, 'Decimal ToCoordinateDms dmsOutput:' + dmsOutput.ToString() + ', dmsExpectedResult:' + dmsExpectedResult);
    dmOutput = dmsOutput.ToCoordinateDm();
    equal(dmOutput.ToString(), dmExpectedResult, 'DMS ToCoordinateDm dmOutput:' + dmOutput.ToString() + ', dmExpectedResult:' + dmExpectedResult);
});
test("CoordinateConverter Formats -41.877518, 146.760986", function () {
    var input = "-41.877518, 146.760986";
    var dmsConverter = new GeoConverter.Providers.DecimalAndDmsConverter();
    var dmsExpectedResult = "S 41°52'39.0648\", E 146°45'39.5496\"";
    var dmsOutput = dmsConverter.ParseCoordinateDms(input);
    equal(dmsOutput.ToString(), dmsExpectedResult, 'DMS  dmsOutput:' + dmsOutput.ToString() + ', dmsExpectedResult:' + dmsExpectedResult);
    var decimalExpectedResult = "-41.877518, 146.760986";
    var decimalOutput = dmsOutput.ToCoordinateDecimal();
    equal(decimalOutput.ToString(), decimalExpectedResult, 'DMS ToCoordinateDecimal decimalOutput:' + decimalOutput.ToString() + ', decimalExpectedResult:' + decimalExpectedResult);
    var dmExpectedResult = "S 41°52.65108\", E 146°45.65916\"";
    var dmOutput = decimalOutput.ToCoordinateDm();
    equal(dmOutput.ToString(), dmExpectedResult, 'Decimal ToCoordinateDm dmOutput:' + dmOutput.ToString() + ', dmExpectedResult:' + dmExpectedResult);
    decimalOutput = dmOutput.ToCoordinateDecimal();
    equal(decimalOutput.ToString(), decimalExpectedResult, 'Dm ToCoordinateDecimal DecimalOutput:' + decimalOutput.ToString() + ', decimalExpectedResult:' + decimalExpectedResult);
    dmsOutput = decimalOutput.ToCoordinateDms();
    equal(dmsOutput.ToString(), dmsExpectedResult, 'Decimal ToCoordinateDms dmsOutput:' + dmsOutput.ToString() + ', dmsExpectedResult:' + dmsExpectedResult);
    dmOutput = dmsOutput.ToCoordinateDm();
    equal(dmOutput.ToString(), dmExpectedResult, 'DMS ToCoordinateDm dmOutput:' + dmOutput.ToString() + ', dmExpectedResult:' + dmExpectedResult);
});
